<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>资金到位</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/themes/icon.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/buttons.css" />
<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-form.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/datagrid-detailview.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/util/jquery.cookie.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/YMLib.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/YWLib.js"></script>
<style type="text/css">.table{border: 1px solid #FFE7BA;} .table tr{border: 1px solid #FFE7BA;} .table tr td{border: 1px solid #FFE7BA;}</style>
<script type="text/javascript">
function yzsz(id){
	if(isNaN(Number($(id).val()))){  
		//当输入不是数字的时候，Number后返回的值是NaN;然后用isNaN判断。
        alert('请填入数字！');
        $(id).val('');
		$(id).focus();
    }
}

function sumDfzc(){
	$('#dfzc').val(parseFloat($('#dszc').val() === "" ?0:$('#dszc').val())
			+parseFloat($('#qxzc').val() === "" ?0:$('#qxzc').val())
			+parseFloat($('#qtzc').val() === "" ?0:$('#qtzc').val()) );

}
$(function(){
	
	$.ajax({
		type:'post',
		url:'/jxcsxm/zjbf/queryBfByid.do',
		data:'id='+parent.YMLib.Var.id,
		dataType:'json',
		success:function(msg){
			$('#submit').form("load",msg);
			yztz=msg.ztz;
			$("#tbsj").val(msg.tbsj);
			$('#bd1').combo('setText',msg.bd);
			
			loadWhBmbm('jhxdwh1',parent.parent.YMLib.Var.xmbm,msg.jhxdwh);
			$("#id").val(parent.YMLib.Var.id);
		}
	});
	
	$("#xmbm").val(parent.parent.YMLib.Var.xmbm);
	
})
var yztz=0;//用于计算是否超出计划下达
function zjbftj(){
	if($('#bd1').combo("getText")==""){alert("请选择或输入标段");return;}
	if($('#jhxdwh1').combo("getValue")==""){alert("请选择计划下达文号");return;}
	
	$('#bd').val($('#bd1').combo("getText"));
	//$('#tbsj').val($('#tbsj1').datebox("getValue"));
	$('#jhxdwh').val($('#jhxdwh1').combo("getValue"));
	var result=true;var ztz=0;
	var cgs = $("#cgs").val()==""?0:$("#cgs").val();
	var gz = $("#gz").val()==""?0:$("#gz").val();
	var sz = $("#sz").val()==""?0:$("#sz").val();
	var zq = $("#zq").val()==""?0:$("#zq").val();
	var tdk = $("#tdk").val()==""?0:$("#tdk").val();
	var jl = $("#jl").val()==""?0:$("#jl").val();
	var rys = $("#rys").val()==""?0:$("#rys").val();
	var cgsjl = $("#cgsjl").val()==""?0:$("#cgsjl").val();
	var ttc = $("#ttc").val()==""?0:$("#ttc").val();
	var stz = $("#stz").val()==""?0:$("#stz").val();
	var dfzc = $("#dfzc").val()==""?0:$("#dfzc").val();
	var yhdk = $("#yhdk").val()==""?0:$("#yhdk").val();
	result=validateInput("cgs","number",result);
	if(result) ztz=accAdd(ztz,cgs);
	result=validateInput("gz","number",result);
	if(result) ztz=accAdd(ztz,gz);
	result=validateInput("sz","number",result);
	if(result) ztz=accAdd(ztz,sz);
	result=validateInput("zq","number",result);
	if(result) ztz=accAdd(ztz,zq);
	result=validateInput("tdk","number",result);
	if(result) ztz=accAdd(ztz,tdk);
	result=validateInput("jl","number",result);
	if(result) ztz=accAdd(ztz,jl);
	result=validateInput("rys","number",result);
	if(result) ztz=accAdd(ztz,rys);
	result=validateInput("stz","number",result);
	if(result) ztz=accAdd(ztz,stz);
	result=validateInput("cgsjl","number",result);
	if(result) ztz=accAdd(ztz,cgsjl);
	result=validateInput("qt","number",result);
	if(result) ztz=accAdd(ztz,$("#qt").val()==""?0:$("#qt").val());
	result=validateInput("ttc","number",result);
	if(result) ztz=accAdd(ztz,ttc;
	var zbz=ztz;
	result=validateInput("dfzc","number",result);
	if(result) ztz=accAdd(ztz,dfzc);
	$('#ztz').val(ztz);
	var dyjhz = false;var dyjhb = false;
	var dyrys = false; var dystz = false;
	var dycgs = false; var dygz = false;
	var dysz = false; var dyzq = false;
	var dytdk = false; var dyjl = false;
	var dyttc = false; var dycgsjl = false;
	var xmbm=parent.parent.YMLib.Var.xmbm;var jhxdwh=$('#jhxdwh1').combo("getValue");
	var dwzj=0;var dwzbz=0;
	var dwcgs = 0; // 车购税
	var dwgz = 0; // 国债
	var dwsz = 0; // 省债
	var dwzq = 0; // 债券
	var dwtdk = 0; // 厅贷款
	var dwjl = 0; // 省奖励
	var dwrys = 0; // 燃油税
	var dwdfzc = 0; // 地方自筹
	var dwyhdk = 0; // 养护贷款
	var dwstz = 0; // 省投资
	var dwcgsjl = 0; // 车购税奖励
	var dwzddzjl = 0; // 重点清单资金
	var dwttc = 0; // 厅统筹
	
	
	$.ajax({
		type:'post',
		url:'/jxcsxm/jhcx/getbfByWhbj.do',
		data:"xmjbxx.jhxdwh="+jhxdwh+"&xmjbxx.xmbm="+xmbm+"&xmjbxx.id="+parent.YMLib.Var.id,
		dataType:'json',
		async:false,
		success:function(msg){
			if(msg!=null){
				dwzj=msg.dwzj;dwzbz=msg.dwzbz;
				dwcgs = msg.cgs; dwgz = msg.gz; dwsz = msg.sz;
				dwzq = msg.zq; dwtdk = msg.tdk; dwrys = msg.rys;
				dwdfzc = msg.dfzc; dwyhdk = msg.yhdk; dwstz = msg.stz;
				dwjl = msg.jl;
				dwcgsjl = msg.cgsjl; dwzddzjl = msg.zddzjl; dwttc = msg.ttc;
			}
		}
	});
	$.ajax({
		type:'post',
		url:'/jxcsxm/jhcx/getdwByWh.do',
		data:"xmjbxx.jhxdwh="+jhxdwh+"&xmjbxx.xmbm="+xmbm,
		dataType:'json',
		async:false,
		success:function(msg){
            if(msg!=null){
                if(parseFloat(msg.dwzj)<parseFloat(accAdd(ztz,dwzj))){
                    dyjhz=true;
                }
                if(parseFloat(msg.dwzbz)<parseFloat(accAdd(zbz,dwzbz))){
                    dyjhb=true;
                }
				if(parseFloat(msg.rys)<parseFloat(accAdd(rys, dwrys))){
					dyrys = true;
				}
				if(parseFloat(msg.stz)<parseFloat(accAdd(stz,dwstz))){
					dystz = true;
				}
				if(parseFloat(msg.cgs)<parseFloat(accAdd(cgs,dwcgs))){
					dycgs = true;
				}
				if(parseFloat(msg.gz)<parseFloat(accAdd(gz,dwgz))){
					dygz = true;
				}
				if(parseFloat(msg.sz)<parseFloat(accAdd(sz,dwsz))){
					dysz = true;
				}
				if(parseFloat(msg.zq)<parseFloat(accAdd(zq,dwzq))){
					dyzq = true;
				}
				if(parseFloat(msg.tdk)<parseFloat(accAdd(tdk,dwtdk))){
					dytdk = true;
				}
				if(parseFloat(msg.jl)<parseFloat(accAdd(jl,dwjl))){
					dyjl = true;
				}
				if(parseFloat(msg.ttc)<parseFloat(accAdd(ttc,dwttc))){
					dyttc = true;
				}
				if(parseFloat(msg.cgsjl)<parseFloat(accAdd(cgsjl,dwcgsjl))){
					dycgsjl = true;
				}
            }
			
		}
	});
	if(dyjhz){
		alert("所填总投资大于到位总投资，不允许保存！");
		return;
	}
	if(dyjhb){
		alert("所填总补助大于到位总补助，不允许保存！");
		return;
	}
	if(dyrys){
		alert("所填燃油税大于到位燃油税，不允许保存！");
		return;
	}
	if(dystz){
		alert("所填省投资大于到位省投资，不允许保存！");
		return;
	}
	if(dycgs){
		alert("所填车购税大于到位车购税，不允许保存！");
		return;
	}
	if(dygz){
		alert("所填国债大于到位国债，不允许保存！");
		return;
	}
	if(dysz){
		alert("所填省债大于到位省债，不允许保存！");
		return;
	}
	if(dyzq){
		alert("所填债券大于到位债券，不允许保存！");
		return;
	}
	if(dytdk){
		alert("所填厅贷款大于到位厅贷款，不允许保存！");
		return;
	}
	if(dyjl){
		alert("所填省奖励大于到位省奖励，不允许保存！");
		return;
	}
	if(dyttc){
		alert("所填厅统筹大于到位厅统筹，不允许保存！");
		return;
	}
	if(dycgsjl){
		alert("所填车购税奖励大于到位车购税奖励，不允许保存！");
		return;
	}
	
	
	//验证是否金额是负数，是则提示
	if(parseFloat(ztz)<0||parseFloat(zbz)<0){
		if(!confirm("所填资金为负数，是否继续")){
			return;
		}
	}
	
	if(result){
		$('#submit').ajaxSubmit({
			dataType:'json',
			success:function(msg){
				if(msg){
					alert("保存成功！");
					parent.$("#grid").datagrid('reload');
					parent.getdwTj();
					parent.parent.$("#grid").datagrid('reload');
					parent.parent.loadTj();
					closeWindow();
				}else{
					alert("保存失败！");
					
				}
			},
			error:function(msg){
				alert("保存失败！");
			}
		});
	}else{
		return;
	}
	
}




</script>
</head>
<body>
<script type="text/javascript">

</script>
<form id="submit" action="/jxcsxm/zjbf/updateZjbf.do" method="post">
<table class='table' style="width: 100%; background-color: #FFE7BA; font-size: 12px"
			border="0" cellpadding="3" cellspacing="1">
			<tr style="height: 35px;">
				<td style="background-color:#FFEFD5;color: #007DB3; font-weight: bold;width:20%" align="right">
				<font color='red' size='1'>*</font>标段：</td>
				<td style="background-color: #ffffff; height: 20px;width:30%" align="left">
					<select id="bd1" class='easyui-combobox' style="width: 124px">
						<option value="没有标段" >没有标段</option>
					</select>
					<br><span style="color: red">若有标段，请删掉手动输入</span>
					<input type="hidden" name='bd' id="bd" style="width: 120px" />
					<input type="hidden" name='id' id="id" style="width: 120px" />
					<input type="hidden" name='xmbm' id="xmbm" style="width: 120px" />
					<input type="hidden" name='ztz' id="ztz" style="width: 120px" />
					
					
					</td>
				<td style="background-color:#FFEFD5;color: #007DB3; font-weight: bold;width:20%" align="right">
				<font color='red' size='1'>*</font>计划下达文号：</td>
				<td style="background-color: #ffffff; height: 20px;width:30%" align="left">
					<input type="text"  id="jhxdwh1" style="width: 124px" />
					<input type="hidden" name='jhxdwh' id="jhxdwh" style="width: 120px" />
					</td>
				
			</tr>
			<tr style="height: 35px;">
				<td style="background-color:#FFEFD5;color: #007DB3; font-weight: bold;" align="right">
				车购税：</td>
				<td style="background-color: #ffffff; height: 20px;" align="left">
					<input type="text" name="cgs" id="cgs" onchange="yzsz(this)" style="width: 120px" />万元</td>
				<td style="background-color:#FFEFD5;color: #007DB3; font-weight: bold;" align="right">
				国债：</td>
				<td style="background-color: #ffffff; height: 20px;" align="left">
					<input type="text" name="gz" id="gz" onchange="yzsz(this)" style="width: 120px" />万元</td>
				
			</tr>
			<tr style="height: 35px;">
				<td style="background-color:#FFEFD5;color: #007DB3; font-weight: bold;" align="right">
				省债：</td>
				<td style="background-color: #ffffff; height: 20px;" align="left">
					<input type="text" name="sz" id="sz" onchange="yzsz(this)" style="width: 120px" />万元</td>
				<td style="background-color:#FFEFD5;color: #007DB3; font-weight: bold;" align="right">
				债券：</td>
				<td style="background-color: #ffffff; height: 20px;" align="left">
					<input type="text" name="zq" id="zq" onchange="yzsz(this)" style="width: 120px" />万元</td>
				
			</tr>
			<tr style="height: 35px;">
				<td style="background-color:#FFEFD5;color: #007DB3; font-weight: bold;" align="right">
				厅贷款：</td>
				<td style="background-color: #ffffff; height: 20px;" align="left">
					<input type="text" name="tdk" id="tdk" onchange="yzsz(this)" style="width: 120px" />万元</td>
				<td style="background-color:#FFEFD5;color: #007DB3; font-weight: bold;" align="right">
				省奖励：</td>
				<td style="background-color: #ffffff; height: 20px;" align="left">
					<input type="text" name="jl" id="jl" onchange="yzsz(this)" style="width: 120px" />万元</td>
			</tr>
			<tr style="height: 35px;">
				<td style="background-color:#FFEFD5;color: #007DB3; font-weight: bold;" align="right">
				燃油税：</td>
				<td style="background-color: #ffffff; height: 20px;" align="left">
					<input type="text" name="rys" id="rys" onchange="yzsz(this)" style="width: 120px" />万元</td>
				<td style="background-color:#FFEFD5;color: #007DB3; font-weight: bold;" align="right">
				省投资：</td>
				<td style="background-color: #ffffff; height: 20px;" align="left">
				<input type="text" name="stz" id="stz" onchange="yzsz(this)" style="width: 120px" />万元</td>
			</tr>
			<tr style="height: 35px;">
				<td style="background-color:#FFEFD5;color: #007DB3; font-weight: bold;" align="right">
					车购税奖励：</td>
				<td style="background-color: #ffffff; height: 20px;" align="left">
					<input type="text" name="cgsjl" id="cgsjl" onchange="yzsz(this)" style="width: 120px" />万元</td>
				<td style="background-color:#FFEFD5;color: #007DB3; font-weight: bold;" align="right">
				其他：</td>
				<td style="background-color: #ffffff; height: 20px;" align="left">
					<input type="text" name="qt" id="qt" onchange="yzsz(this)" style="width: 120px" />万元</td>
			</tr>
			<tr style="height: 35px;">
				<td style="background-color:#FFEFD5;color: #007DB3; font-weight: bold;" align="right">
					银行贷款：</td>
				<td style="background-color: #ffffff; height: 20px;" align="left">
					<input type="text" name="yhdk" id="yhdk" onchange="yzsz(this)" style="width: 120px" />万元</td>
				<td style="background-color:#FFEFD5;color: #007DB3; font-weight: bold;" align="right">
				地方自筹：</td>
				<td style="background-color: #ffffff; height: 20px;" align="left">
					<input type="text" name="dfzc" id="dfzc" readonly style="width: 120px" />万元</td>
			</tr>
			<tr style="height: 35px;">
				<td style="background-color:#FFEFD5;color: #007DB3; font-weight: bold;" align="right">
					厅统筹：
				</td>
				<td style="background-color: #ffffff; height: 20px;" align="left">
					<input type="text" name="ttc" id="ttc" onchange="yzsz(this)" style="width: 120px" />万元
				</td>
				<td style="background-color:#FFEFD5;color: #007DB3; font-weight: bold;" align="right">
				拨付月份：
				</td>
				<td style="background-color: #ffffff; height: 20px;" align="left">
                 <input type="text" name='bfyf' id="bfyf" style="width: 120px" readonly="readonly"/>
                </td>

			</tr>
	<tr style="height: 35px;">
		<td style="background-color:#FFEFD5;color: #007DB3; font-weight: bold;" align="right">
			地市财政自筹：
		</td>
		<td style="background-color: #ffffff; height: 20px;" align="left">
			<input type="text" name="dszc" id="dszc" onchange="yzsz(this)" style="width: 120px"  oninput="sumDfzc()"/>万元
		</td>
		<td style="background-color:#FFEFD5;color: #007DB3; font-weight: bold;" align="right">
			区县财政自筹：</td>
		<td style="background-color: #ffffff; height: 20px;" align="left">
			<input type="text" name="qxzc" id="qxzc" onchange="yzsz(this)" style="width: 120px" oninput="sumDfzc()"/>万元</td>
	</tr>
			<tr style="height: 35px;">
				<td style="background-color:#FFEFD5;color: #007DB3; font-weight: bold;" align="right">
					其他自筹：
				</td>
				<td style="background-color: #ffffff; height: 20px;" align="left">
					<input type="text" name="qtzc" id="qtzc" onchange="yzsz(this)" style="width: 120px" oninput="sumDfzc()"/>万元
				</td>
				<td style="background-color:#FFEFD5;color: #007DB3; font-weight: bold;" align="right">
				填报人：</td>
				<td style="background-color: #ffffff; height: 20px;" align="left">
					<input type="text" name="tbr" id="tbr" style="width: 120px" /></td>
			</tr>
	<tr style="height: 35px;">
		<td style="background-color:#FFEFD5;color: #007DB3; font-weight: bold;" align="right">
			填报时间：
		</td>
		<td style="background-color: #ffffff; height: 20px;" align="left">
			<input type="text" name="tbsj" id="tbsj" style="width: 124px" readonly="readonly"/>
		</td>
		<td style="background-color:#FFEFD5;color: #007DB3; font-weight: bold;" align="right">
		</td>
		<td style="background-color: #ffffff; height: 20px;" align="left">
		</td>
	</tr>
			<tr style="height: 35px;">
				<td style="background-color:#FFEFD5;color: #007DB3; font-weight: bold;" align="right">
				备注：</td>
				<td colspan="3" style="background-color: #ffffff; height: 20px;" align="left">
					<textarea name="bz" id="bz" rows="2" style="width: 310px;"></textarea>
				
			</tr>
			<tr style="height: 35px;">
				<td colspan="4" style="background-color: #ffffff;"align="center">
				<a id='mybuttion1' style="margin-left: 5px;margin-bottom: 1px;" href="javascript:zjbftj()" onmouseover="szgq('button button-tiny button-glow button-rounded button-raised button-primary','mybuttion1')" onmouseout="szgq('button button-tiny button-rounded button-raised button-primary','mybuttion1')"  class="button button-tiny button-rounded button-raised button-primary">保存</a>
				<a id='mybuttion2' style="margin-left: 5px;margin-bottom: 1px;" href="javascript:closeWindow()" onmouseover="szgq('button button-tiny button-glow button-rounded button-raised button-primary','mybuttion2')" onmouseout="szgq('button button-tiny button-rounded button-raised button-primary','mybuttion2')"  class="button button-tiny button-rounded button-raised button-primary">取消</a>
			
			</tr>
		</table>
	</form>
</body>
</html>